export default {
    data() {
        return {
            tableHeight: 0
        };
    },
    methods: {
        calTableHeight() {
            this.$nextTick(() => {
                /**
                 * @params{string}  必须声明ref值ruleForm，所有的高度计算都是基于ref获取表单元素高度
                 *
                 * 返回值
                 *      1.dialogTableHeight 弹窗内表格的高度
                 *      2.tableHeight 弹窗展示区的高度
                 * */
                // 表格高度 = 可视区高度 - 顶部 - 表头高度
                this.tableHeight = window.innerHeight - 190;

                // 减去其他的高度
                if (this.$refs.box1) {
                	if (Reflect.has(this.$refs.box1, 'offsetHeight')) {
		                this.tableHeight -= (this.$refs.box1.offsetHeight) || 0;
	                } else if (Reflect.has(this.$refs.box1.$el, 'offsetHeight')) {
		                this.tableHeight -= (this.$refs.box1.$el.offsetHeight) || 0;
	                }
                }
	            if (this.$refs.box2) {
		            if (Reflect.has(this.$refs.box2, 'offsetHeight')) {
		                this.tableHeight -= (this.$refs.box2.offsetHeight) || 0;
	                } else if (Reflect.has(this.$refs.box2.$el, 'offsetHeight')) {
		                this.tableHeight -= (this.$refs.box2.$el.offsetHeight) || 0;
	                }
                }
                if (this.$refs.box3) {
	                if (Reflect.has(this.$refs.box3, 'offsetHeight')) {
		                this.tableHeight -= (this.$refs.box3.offsetHeight) || 0;
	                } else if (Reflect.has(this.$refs.box3.$el, 'offsetHeight')) {
		                this.tableHeight -= (this.$refs.box3.$el.offsetHeight) || 0;
	                }
                }
	            if (this.$refs.box4) {
		            if (Reflect.has(this.$refs.box4, 'offsetHeight')) {
			            this.tableHeight -= (this.$refs.box4.offsetHeight) || 0;
		            } else if (Reflect.has(this.$refs.box4.$el, 'offsetHeight')) {
			            this.tableHeight -= (this.$refs.box4.$el.offsetHeight) || 0;
		            }
	            }
            });
        }
    },
    mounted() {
        this.calTableHeight();
        addEventListener('resize', () => {
            this.calTableHeight();
        });
    },
	activated() {
		this.calTableHeight();
		addEventListener('resize', () => {
			this.calTableHeight();
		});
	},
    watch: {
        state(newVal) {
            if (newVal) {
                this.$nextTick(() => {
                    this.calTableHeight();
                });
            }
        },
        dialogState(newVal) {
            if (newVal) {
                this.$nextTick(() => {
                    this.calTableHeight();
                });
            }
        },
        saveDialogState(newVal) {
            if (newVal) {
                this.$nextTick(() => {
                    this.calTableHeight();
                });
            } else {
                this.calTableHeight();
            }
        },
        '$store.state.app.appHeight'() {
            this.$nextTick(() => {
                this.calTableHeight();
            });
        }
    }
};
